import {getRole, postRole, putRole} from '@/base/api/RoleApi';
import {Role} from '@/base/model/Role';

export class FormBloc {
  form = new Role();

  load(id: number) {
    return getRole(id)
      .then((res) => {
        this.form = res.data;
      });
  }

  save(id: number | '') {
    const entity: any = {
      description: this.form.description,
      name: this.form.name,
      res: this.form.res
    };
    return id ? putRole(id, entity) : postRole(entity);
  }
}
